/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */

/* 
 * Hum -- The Low-Calorie Music Manager
 * 
 * Copyright (C) 2007 by Brian Davis <brian.william.davis@gmail.com>
 *
 * This file is modifiable/redistributable under the terms of the GNU
 * General Public License.
 *
 * You should have recieved a copy of the GNU General Public License along
 * with this program; see the file COPYING. If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 0211-1307, USA.
 */

#ifndef _HUM_UTILS_H
#define _HUM_UTILS_H

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <tracker.h>

#include <glib/gprintf.h>
#include <gtk/gtk.h>
#include <glade/glade.h>

/*
 * Standard gettext macros.
 */
#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define N_(String) (String)
#  endif
#else
#  define textdomain(String) (String)
#  define gettext(String) (String)
#  define dgettext(Domain,Message) (Message)
#  define dcgettext(Domain,Message,Type) (Message)
#  define bindtextdomain(Domain,Directory) (Domain)
#  define _(String) (String)
#  define N_(String) (String)
#endif

/* For testing propose use the local (not installed) glade file */
/* #define HUM_GLADE_FILE PACKAGE_DATA_DIR"/hum/glade/hum.glade" */
#define HUM_GLADE_FILE "hum.glade"
#define HUM_LOGO_FILE "hum.svg"

#ifdef __cplusplus
extern "C"
{
#endif

#define DEBUG TRUE	

#define HUM_SECONDS_TO_HOURS(t)		((guint) (t / (60 * 60)))
#define HUM_SECONDS_TO_MINUTES(t)	((guint) (t / 60))
#define HUM_SECONDS_TO_SECONDS(t)	((gint) (t / 60) % 60)
#define HUM_TIME_FORMAT_LONG		"i:%02i:%02i"
#define HUM_TIME_FORMAT_SHORT		"i:%02i"
#define HUM_TIME_ARGS_LONG(t)		HUM_SECONDS_TO_HOURS(t), HUM_SECONDS_TO_MINUTES(t), HUM_SECONDS_TO_SECONDS(t)
#define HUM_TIME_ARGS_SHORT(t)		HUM_SECONDS_TO_MINUTES(t), HUM_SECONDS_TO_SECONDS(t)

// FIXME: Fetch more information than we need so that later we can populate a
// 'properties' dialog with it all. 
static char *audio_keys[] =
{
	"Audio:Title",
	"Audio:Artist",
	"Audio:Album",
	"Audio:Genre",
	"Audio:Duration",
	"Audio:TrackNo",
	"File:Size",
	//"Audio:Bitrate",
	//"Audio:ReleaseDate",
	//"Audio:Codec",
	//"DC:Keywords"
};

enum
{
	//AUDIO_URI,
	//AUDIO_SERVICE,
	AUDIO_TITLE,
	AUDIO_ARTIST,
	AUDIO_ALBUM,
	AUDIO_GENRE,
	AUDIO_DURATION,
	AUDIO_TRACK_NO,
	AUDIO_SIZE,
	//AUDIO_BITRATE,
	//AUDIO_RELEASEDATE,
	//AUDIO_CODEC,
	//AUDIO_KEYWORDS,
	AUDIO_N_KEYS
};

typedef struct 
{
	TrackerClient		*client;
	
	guint				total_song_count;
	guint64				total_duration;
	guint64				total_song_size;
	
	GladeXML 			*xml;
	
	GtkWindow 			*window;
	GtkStatusbar		*statusbar;
	GtkToolButton 		*prev_button;
	GtkToggleToolButton *play_button;
	GtkToolButton 		*stop_button;
	GtkToolButton 		*next_button;
	GtkLabel 			*track_label;
	GtkLabel 			*duration_label;
	GtkHScale 			*slider;
	GtkEntry			*search_entry;
	GtkButton			*search_button;
	GtkListStore		*store;
	GtkTreeView			*track_list;
	GtkTreeSelection 	*browse_select;	
	
	GtkDialog			*tag_dialog;
	GtkEntry			*tag_entry;
	GtkButton			*tag_cancel;
	GtkButton			*tag_apply;
} HumApp;

HumApp hum_app;

void hum_init ();
void hum_quit ();

void hum_debug (const gchar* func, gchar* fmt, ...);
gchar *hum_str_from_time (guint64 time);
gchar *hum_str_from_size (guint64 size);
gint hum_utf8_strcmp (gchar *a, gchar *b);
gchar *hum_remove_escapes (gchar *str);

#ifdef __cplusplus
}
#endif

#endif /* _HUM_UTILS_H */
